package com.ccnf.controller;

import com.ccnf.core.bean.Response;
import com.ccnf.core.bean.ResponseWithData;
import com.ccnf.model.ao.SmsAuthAO;
import com.ccnf.service.SaasService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 微信相关API 前端控制器
 * </p>
 *
 * @author developer
 * @since 2018-10-09
 */
@RestController
@RequestMapping("/v1/sms")
@Api(value = "SmsController", description = "短信相关API")
public class SmsController extends BaseController {
    @Autowired
    private SaasService saasService;

    @ApiOperation("发送短信验证码")
    @GetMapping("captcha/send")
    public Response sendSms(String phone) {
        saasService.sendPhoneCaptcha(getTokenParams(), phone);
        return Response.success();
    }

    @ApiOperation("验证短信验证码")
    @GetMapping("captcha/verify")
    public Response sendSms(String phone, String captcha) {
        saasService.verifyPhoneCaptcha(phone, captcha, getTokenParams());
        return Response.success();
    }

    @ApiOperation("短信授权")
    @PostMapping("auth")
    public ResponseWithData smsAuth(@RequestBody SmsAuthAO smsAuthAO) {
        return ResponseWithData.success(saasService.smsUserAuth(smsAuthAO, getTokenParams()));
    }
}